<?php

namespace App\Repos;

use App\Models\Tplmsg;
use App\Models\TplmsgKeyword;
use Log;
class TplmsgRepo 
{
    public static function find($where)
    {
        return Tplmsg::where($where)->first();
    }

    public static function getKeywords($tpl_id,$data)
    {

        $arr = [];
        $list = TplmsgKeyword::where(['tplmsg_id'=>$tpl_id])->get();

        foreach ($list as $k => $v) {
            if($v->default) {
                $value = $v->default;
            } else {
                $value = array_get($data,$v->value);
            }
            $arr[$v->keyword] = $value;
           
            
        }
        return $arr;
    }
}
